import traceback
import sys
import StringIO
from cgi import escape

class PythonException:

  test = "hello world"
  _PTJS_serialize = ["ErrorCode","ErrorMessage"]
  
  def __init__(self,ErrorCode,ErrorMessage):
    self.ErrorCode = ErrorCode
    self.ErrorMessage = ErrorMessage

def packageException():
  # Get the traceback info
  tb = sys.exc_info()
  tb_file = StringIO.StringIO()
  traceback.print_tb(tb[2],file=tb_file)
  tb_file.write(tb[1])
  error_msg = escape(tb_file.getvalue())
  tb_file.close()
  error_code = str(sys.exc_info()[0])
  return PythonException(error_code,error_msg)